﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace MetaSharp.Transformation.Tests.Patterns
{
	public class RangeTests
	{
        [Fact]
		public async Task ReadsLowerCaseLetterSuccessfully()
		{
            var p = Pattern.Range('a', 'z');
            var m = await Pattern.Match(p, "j");
			Assert.Equal('j', m.Value);
		}

        [Fact]
		public async Task ReadsIntSuccessfully()
		{
            var p = Pattern.Range(0, 100);
            var m = await Pattern.Match(p, 11);
			Assert.Equal(11, m.Value);
		}

        [Fact]
		public async Task ReadsLowerboundSuccessfully()
		{
            var p = Pattern.Range(0, 100);
            var m = await Pattern.Match(p, 0);
            Assert.True(m.Matched);
		}

        [Fact]
		public async Task ReadsUpperboundIntSuccessfully()
		{
            var p = Pattern.Range(0, 100);
            var m = await Pattern.Match(p, 100);
            Assert.True(m.Matched);
		}

        [Fact]
		public async Task ReadsWhenLowerAndUpperboundsAreEqualSuccessfully()
		{
            var p = Pattern.Range(0, 0);
            var m = await Pattern.Match(p, 0);
			Assert.Equal(0, m.Value);
		}

        [Fact]
		public async Task ReadsNegativeRangeSuccessfully()
		{
            var p = Pattern.Range(-100, 0);
            var m = await Pattern.Match(p, -10);
			Assert.Equal(-10, m.Value);
		}

        [Fact]
        public void FromMustbeComparativelySmalleThanTo()
        {
            Assert.Throws<ArgumentException>(() => Pattern.Range(1, 0));
        }

        [Fact]
		public async Task FailsToReadEmptyStream()
		{
            var p = Pattern.Range(0, 1);
            var m = await Pattern.Match(p, new object[0]);
            Assert.False(m.Matched);
		}

        [Fact]
		public async Task FailsToReadWrongType()
		{
            var p = Pattern.Range(0, 1);
            var m = await Pattern.Match(p, 1.0);
			Assert.False(m.Matched);
		}
	}
}
